#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：UserMapper.py
@Author ：zqy
@Email : zqingy@work@163.com
@note:
"""

from typing import Optional

from application.mapper import BaseMapper
from application.model.UserModel import User


class UserMapper(BaseMapper):
    """
    用户Mapper
    """
    model: User = User

    @classmethod
    def get_info_by_phone(cls, phone: int) -> Optional[User]:
        """
        根据用户名获取用户信息
        :param phone: 用户名
        :return: 用户信息 | None
        """
        return cls.model.query.filter_by(phone=phone).first()

    @classmethod
    def get_info_by_username(cls, username: str) -> Optional[User]:
        """
        根据用户名获取用户信息
        :param username: 用户名
        :return: 用户信息 | None
        """
        return cls.model.query.filter_by(username=username).first()
